package com.example.denglu;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.example.denglu.SetHttpFrament.Img1Fragment;
import com.example.denglu.SetHttpFrament.Img2Fragment;
import com.example.denglu.SetHttpFrament.Img3Fragment;

import java.util.ArrayList;
import java.util.List;

public class SetHttpActivity extends AppCompatActivity {

    private ViewPager2 MyVp;
    private List<Fragment> fragments;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_http);
        initView();
        addFragment();
    }

    private void addFragment() {
        fragments = new ArrayList<>();
        fragments.add(new Img1Fragment());
        fragments.add(new Img2Fragment());
        fragments.add(new Img3Fragment());
        MyVp.setAdapter(new FragmentStateAdapter(getSupportFragmentManager(),getLifecycle()) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                return fragments.get(position);
            }

            @Override
            public int getItemCount() {
                return fragments.size();
            }
        });
    }

    private void initView() {
        MyVp = findViewById(R.id.My_Vp);

    }
}